package com.sa07.ui.uitls;

import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import java.awt.Point;
import java.awt.Toolkit;

/**
 * ui工具
 * 
 * @author Long.shangbo
 *
 * 2014-2-14 下午11:41:46
 */
public class UiTools {
	
	private static final GridBagConstraints constraints = new GridBagConstraints();
	
	static{
		constraints.fill = GridBagConstraints.HORIZONTAL;
		constraints.insets = new Insets(5, 5, 5, 5);
	}
	
	/**
	 * 设置窗口居中
	 * @param widht
	 * @param height
	 */
	public static Point getCenterPosition(int width, int height){
		Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize();
		int x = (screenDim.width - width) / 2;
		int y = (screenDim.height - height) / 2;
		return new Point(x, y);
	}
	
	/**
	 * 获得布局的约束
	 * @param gridx
	 * @param gridy
	 * @param gridwidth
	 * @param gridheight
	 * @param weightx
	 * @param weighty
	 * @param ipadx
	 * @return
	 */
	public static GridBagConstraints getConstraint(int gridx, int gridy,
			int gridwidth, int gridheight, double weightx, double weighty,
			int ipadx) {
		constraints.gridx = gridx;
		constraints.gridy = gridy;
		constraints.gridwidth = gridwidth;
		constraints.gridheight = gridheight;
		constraints.weightx = weightx;
		constraints.weighty = weighty;
		constraints.anchor = GridBagConstraints.WEST;
		constraints.ipadx = ipadx;
		return constraints;
}
}
